import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import CpasTable from "../ExcelGrid";
import "./_style.less";
import AntTabs from "~/public/cpas-ui/components-ui/ant-components/AntTab";
import { Button, Space } from "antd";
import CheckDetailsModal from "../ExcelGrid/components/Validator/CheckDetails";
import CpasEditor from "../../components-bs/Editor/index";
import notify from "devextreme/ui/notify";
import { DevButton } from "~/public/cpas-ui";
import { LoadIndicator } from "devextreme-react";
import { getCurrentSysName, SystemName, MergeType, getHbTypeByZcbfid, isFirstCharEqual, transformCrossData, } from "../../tools/Tools";
import DsBase from "./DSBase";
export var E_CpasTableDescCategory;
(function (E_CpasTableDescCategory) {
    E_CpasTableDescCategory["DC"] = "disclosureContent";
    E_CpasTableDescCategory["DCN"] = "disclosureContentNote";
    E_CpasTableDescCategory["ZL_DC"] = "zlDisclosureContent";
    E_CpasTableDescCategory["ZL_DCN"] = "zlDisclosureContentNote";
})(E_CpasTableDescCategory || (E_CpasTableDescCategory = {}));
const XMType = window.sessionStorage.electronParams
    ? JSON.parse(window.sessionStorage.electronParams)?.params?.XMType
    : "单机审计项目";
/**
 *
 * import CpasTableInput from  "~/public/cpas-ui/components-bs/HandsonTable"
 *
 */
class CpasHandsonTableDs extends DsBase {
    // zlTableRef = React.createRef<HandSonGrid>(); //容器Ref
    // //标题注解ref
    // titleEditorRef = React.createRef<CpasEditor>();
    // //内容注解ref
    // contentEditorRef = React.createRef<CpasEditor>();
    // cpasstableWapperRef: any = React.createRef<any>();
    // zlCpasTableRef = [];
    constructor(props) {
        super(props);
        console.log("props--", props);
        // this.state = {
        //   isShowDsMenuBar: false,
        //   isShowZlMenuBar: false,
        //   isOpenDetails: false,
        //   showDismantledTable: false,
        //   result: [],
        //   resultList: [],
        //   tabValue: "1",
        //   isBackAll: false,
        //   zlCpasTable: [],
        //   reCalculateFormulaLoading: false,
        //   reSyncLoading: false,
        // };
        // this.onShowDetailsModal = this.onShowDetailsModal.bind(this);
        // this.tabModelChanges = this.tabModelChanges.bind(this);
        // this.onFocusOutCallback = this.onFocusOutCallback.bind(this);
        // this.setZlCpasTableRefs = this.setZlCpasTableRefs.bind(this);
        // this.beforeJsonExport = this.beforeJsonExport.bind(this);
        // this.beforeJsonImport = this.beforeJsonImport.bind(this);
    }
    handleSaveData = async (name, tid, data_id, action) => {
        return this.commonSaveData(name, tid, data_id, action);
    };
    render() {
        const { showDismantledTable } = this.state;
        const { renderRightButton, renderLeftButton } = this.props;
        const sysName = getCurrentSysName();
        const isSyncButton = sysName !== SystemName.MERGE && XMType !== "单机审计项目";
        const mergeType = getHbTypeByZcbfid();
        return (_jsxs("div", { className: "cpas-table-ds-container", children: [_jsxs(AntTabs, { onChange: this.tabModelChanges, activeKey: this.state.tabValue, 
                    // defaultActiveKey={"1"}
                    tabPosition: "top", children: [_jsxs(AntTabs.Panel, { tab: `附注`, className: "fz-tab-content", children: [_jsxs("div", { className: "cpas-table-ds-header", children: [_jsxs(Space, { style: { marginRight: 0 }, children: [renderLeftButton && renderLeftButton(), _jsx(DevButton, { stylingMode: "outlined", className: "cpas-ds-outline-button", text: "模板设计", onClick: () => {
                                                        this.setState({
                                                            isShowDsMenuBar: !this.state.isShowDsMenuBar,
                                                        });
                                                    } }), _jsxs(DevButton, { width: 80, stylingMode: "outlined", className: "cpas-loading-button", onClick: async () => {
                                                        this.setState({
                                                            reCalculateFormulaLoading: true,
                                                        });
                                                        const { tid = "" } = this.props.notes;
                                                        const zlTid = `${tid}-zl`;
                                                        const zlTableRef = this?.zlTableRef?.current;
                                                        const zlArtVerifyFormulaList = zlTableRef?.articulationVerifyService
                                                            ?.artVerifyFormulaList;
                                                        await this.props.innerRef.current.reCalculateFormula(async (verifyData) => {
                                                            //接口返回的数据有等号，需要过滤掉。前端展示不需要
                                                            if (verifyData && verifyData.length) {
                                                                for (let i = 0; i < verifyData.length; i++) {
                                                                    let { beVerifiedFormula = "", verifyFormula = "" } = verifyData[i];
                                                                    if (isFirstCharEqual(beVerifiedFormula)) {
                                                                        beVerifiedFormula = beVerifiedFormula.slice(1);
                                                                    }
                                                                    if (isFirstCharEqual(verifyFormula)) {
                                                                        verifyFormula = verifyFormula.slice(1);
                                                                    }
                                                                    verifyData[i]["beVerifiedFormula"] =
                                                                        beVerifiedFormula;
                                                                    verifyData[i]["verifyFormula"] = verifyFormula;
                                                                }
                                                            }
                                                            const result = await zlTableRef.articulationVerifyService.generateArtVerifyFormula(verifyData, zlTid);
                                                            if (result && result.length) {
                                                                const { parentFormula, childFormula, otherChildFormula, } = await zlTableRef.articulationVerifyService.formatDynamicFormula(result, zlTid);
                                                                const createDataList = verifyData.filter((item) => item.dynamicType !== "MAIN" &&
                                                                    item.dynamicType !== "CHILD" &&
                                                                    !item.dynamicCondition);
                                                                zlTableRef.articulationVerifyService.artVerifyFormulaList =
                                                                    [
                                                                        ...parentFormula,
                                                                        ...childFormula,
                                                                        ...otherChildFormula,
                                                                        ...createDataList,
                                                                    ];
                                                            }
                                                            else if (verifyData && verifyData.length) {
                                                                zlTableRef.articulationVerifyService.artVerifyFormulaList =
                                                                    [...verifyData];
                                                            }
                                                        }, true, zlArtVerifyFormulaList);
                                                        this.setState({
                                                            reCalculateFormulaLoading: false,
                                                        });
                                                    }, children: [_jsx(LoadIndicator, { style: {
                                                                marginRight: 5,
                                                            }, width: 20, height: 20, className: "button-indicator", visible: this.state.reCalculateFormulaLoading }), _jsx("span", { className: "dx-button-text", children: "\u91CD\u7B97" })] }), isSyncButton && (_jsxs(DevButton, { width: 70, stylingMode: "outlined", className: "cpas-loading-button", onClick: async () => {
                                                        this.setState({
                                                            reSyncLoading: true,
                                                        });
                                                        if (this.props.onSynchronous) {
                                                            await this.props.onSynchronous();
                                                        }
                                                        this.setState({
                                                            reSyncLoading: false,
                                                        });
                                                    }, children: [_jsx(LoadIndicator, { style: {
                                                                marginRight: 5,
                                                            }, width: 20, height: 20, className: "button-indicator", visible: this.state.reSyncLoading }), _jsx("span", { className: "dx-button-text", children: "\u540C\u6B65" })] })), renderRightButton && renderRightButton()] }), _jsx("div", { className: "design-vert-line" })] }), _jsx(CpasTable, { type: "ds", name: "自定义披露表", formulaTimeSlice: true, tabLevel: 3, beforeJsonExport: this.beforeJsonExport, beforeJsonImport: this.beforeJsonImport, verifyMode: true, tabGroup: "tab-ds-group", ref: this.props.innerRef, afterOnArtCellClick: (a, arr, cb) => {
                                        let p = [];
                                        const resultList = transformCrossData(this.zlTableRef.current.articulationVerifyService
                                            .artParseResultList);
                                        if (cb !== null && cb[0]) {
                                            resultList.map((item) => {
                                                const currentFormula = cb[0].currentFormula;
                                                //附注整理右键校验支持交叉校验
                                                let havePro = item.beVerifiedCoordsMap;
                                                if (havePro?.hasOwnProperty(currentFormula)) {
                                                    p.push(item);
                                                }
                                            });
                                            this.setState({
                                                result: p,
                                                isBackAll: true,
                                            });
                                            this.onShowDetailsModal();
                                        }
                                        else {
                                            return notify("非校验项/已校验通过!", "error", 2000);
                                        }
                                    }, topBar: _jsxs("div", { className: "cpas-table-ds-bar-container", children: [_jsx("div", { className: "cpas-table-ds-title", children: _jsx("span", { children: this.props.title }) }), _jsx("div", { className: "cpas-table-ds-input", children: _jsx(CpasEditor, { ref: this.titleEditorRef, tableRef: this.props.innerRef, placeholder: "\u5728\u6B64\u8F93\u5165\u9644\u6CE8\u4E2D\u62AB\u9732\u5185\u5BB9", onFocusOut: () => this.onFocusOutCallback("title") }) })] }), bottomBar: _jsx(_Fragment, { children: _jsx("div", { className: "cpas-table-ds-input cpas-table-ds-bottom-input", children: _jsx(CpasEditor, { tableRef: this.props.innerRef, ref: this.contentEditorRef, placeholder: "\u82E5\u5355\u4F53\u9644\u6CE8\u4E2D\u5B58\u5728\u5BF9\u4E0A\u8FF0\u62AB\u9732\u5185\u5BB9\u7684\u6CE8\u91CA\uFF0C\u8BF7\u5728\u6B64\u8F93\u5165", onFocusOut: () => this.onFocusOutCallback("content") }) }) }), mapRowsList: [], mapColumnsList: [], isShowMenuToolBar: this.state.isShowDsMenuBar, gridData: this.props.gridData, ...this.props, numberZeroReplace: " " })] }, "1"), _jsxs(AntTabs.Panel, { forceRender: true, tab: `整理`, className: "zl-tab-content", children: [_jsxs("div", { className: "cpas-table-ds-header", children: [_jsxs(Space, { style: { marginRight: 0 }, children: [mergeType === MergeType.TEMPLATE ? null : (_jsx(Button, { size: "small", 
                                                    // disabled={true}
                                                    onClick: () => {
                                                        console.log(this.zlTableRef);
                                                        this.setState({
                                                            isBackAll: false,
                                                            result: this.zlTableRef.current?.articulationVerifyService
                                                                .artParseResultList,
                                                            resultList: this.zlTableRef.current?.articulationVerifyService
                                                                .artVerifyFormulaList,
                                                        });
                                                        this.onShowDetailsModal();
                                                    }, children: "\u6821\u9A8C\u8BE6\u60C5" })), _jsx(Button, { onClick: () => {
                                                        this.zlTableRef.current?.menuToolRef?.current?.reductionEditorRef?.current?.setIsHiddenMergeRow(this.zlTableRef.current?.tableConfig?.filterCfg?.num
                                                            ? true
                                                            : false);
                                                        this.setState({
                                                            isShowZlMenuBar: !this.state.isShowZlMenuBar,
                                                        });
                                                    }, size: "small", children: "\u6574\u7406\u8BBE\u8BA1" })] }), _jsx("div", { className: "design-vert-line" })] }), _jsx("div", { ref: this.cpasstableWapperRef, id: "cpasstableWapperRef", children: _jsx(CpasTable, { tabLevel: 3, tabGroup: "tab-ds-group", verifyMode: true, hiddenTableContainer: true, mapRowsList: [], mapColumnsList: [], isShowMenuToolBar: this.state.isShowZlMenuBar, gridData: this.props.gridData, ref: this.zlTableRef, afterOnArtCellClick: (a, arr, cb) => {
                                            let p = [];
                                            const resultList = transformCrossData(this.zlTableRef.current.articulationVerifyService
                                                .artParseResultList);
                                            if (cb !== null && cb[0]) {
                                                resultList.map((item) => {
                                                    const currentFormula = cb[0].currentFormula;
                                                    //附注整理右键校验支持交叉校验
                                                    let havePro = item.beVerifiedCoordsMap;
                                                    if (havePro?.hasOwnProperty(currentFormula)) {
                                                        p.push(item);
                                                    }
                                                });
                                                this.setState({
                                                    result: p,
                                                    isBackAll: true,
                                                });
                                                this.onShowDetailsModal();
                                            }
                                            else {
                                                return notify("非校验项/已校验通过!", "error", 2000);
                                            }
                                        }, ...this.props, type: "zl", dsTableRef: this, numberZeroReplace: " " }) }), _jsx("div", { className: "zl-table-wapper", children: _jsx("div", { id: "cpasstableWapperRef2", style: {
                                            height: this.state.isShowZlMenuBar
                                                ? "calc(100% - 150px)"
                                                : "100%",
                                            display: showDismantledTable ? "block" : "none",
                                            overflowY: "auto",
                                        }, children: "\u8FD9\u91CC\u663E\u793A\u62C6\u8868\u540E\u7684\u6570\u636E" }) })] }, "2")] }), _jsx(CheckDetailsModal, { isOpen: this.state.isOpenDetails, handleOpen: this.onShowDetailsModal, result: this.state.result, onBackAll: this.onBackAll, isBackAll: this.state.isBackAll, resultList: this.state.resultList, params: this.zlTableRef })] }));
    }
}
export default CpasHandsonTableDs;
